home *** CD-ROM | disk | FTP | other *** search
/ CICA 1993 April / CICA MS Windows - April 1993.iso / unzipped / programr / listings / ptv2n5 / l1.asm < prev    next >
Assembly Source File  |  1991-09-06  |  1KB  |  35 lines

  1. ;-----------------------------------------------------------
  2. ; Sorts an array of ints.  C callable (small model).  25 bytes.
  3. ; void sort( int num, int a[] );
  4. ;
  5. ; Courtesy of David Stafford.
  6. ;-----------------------------------------------------------
  7.  
  8.     .model small
  9.     .code
  10.         public _sort
  11.  
  12. top:    mov     dx,[bx]         ;swap two adjacent integers
  13.         xchg    dx,[bx+2]
  14.         xchg    dx,[bx]
  15.  
  16.         cmp     dx,[bx]         ;did we put them in the right order?
  17.         jl      top             ;no, swap them back
  18.  
  19.         inc     bx              ;go to next integer
  20.         inc     bx
  21.         loop    top
  22.  
  23. _sort:  pop     dx              ;get return address (entry point)
  24.         pop     cx              ;get count
  25.         pop     bx              ;get pointer
  26.         push    bx              ;restore pointer
  27.         dec     cx              ;decrement count
  28.         push    cx              ;save count
  29.         push    dx              ;restore return address
  30.         jg      top             ;if cx > 0
  31.  
  32.         ret
  33.  
  34.     end
  35.